package com.jeasonzhao.commons.parser.expression;

public class SyntaxNodeCollection extends java.util.Vector<SyntaxNode>
{
    private static final long serialVersionUID = 1L;
    public SyntaxNodeCollection()
    {
        super();
    }

    public static SyntaxNodeCollection from(SyntaxNode[] arys)
    {
        if(null == arys)
        {
            return null;
        }
        SyntaxNodeCollection ret = new SyntaxNodeCollection();
        for(int n = 0;n < arys.length;n++)
        {
            ret.addElement(arys[n]);
        }
        return ret;
    }

    public static SyntaxNodeCollection from(java.lang.Iterable<SyntaxNode> list)
    {
        if(null == list)
        {
            return null;
        }
        SyntaxNodeCollection ret = new SyntaxNodeCollection();
        java.util.Iterator<SyntaxNode> it = list.iterator();
        while(it.hasNext())
        {
            ret.add(it.next());
        }
        return ret;
    }

    public void addAll(java.lang.Iterable<SyntaxNode> list)
    {
        if(null == list)
        {
            return;
        }
        java.util.Iterator<SyntaxNode> it = list.iterator();
        while(it.hasNext())
        {
            this.add(it.next());
        }
    }

    public void addAll(SyntaxNode[] colls)
    {
        if(null == colls)
        {
            return;
        }
        for(int n = 0;n < colls.length;n++)
        {
            this.add(colls[n]);
        }
    }

    public void compress()
    {
        for(int n = 0;n <= this.size();n++)
        {
            if(this.elementAt(n) == null)
            {
                this.removeElementAt(n);
                n = n == 0 ? 0 : n - 1;
            }
        }
    }

    public String toString()
    {
        return toString(" ",false);
    }

    public String toString(String str,boolean appendAtFirst)
    {
        StringBuffer strRet = new StringBuffer();
        for(int n = 0;n < this.size();n++)
        {
            if(n > 0 || appendAtFirst)
            {
                strRet.append(str);
            }
            strRet.append(this.elementAt(n));
        }
        return strRet.toString();
    }

}
